<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('会员管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>会员姓名：</label>
                                <input type="text" name="nameVip"/>
                            </li>
                            <li>
                                <label>手机号：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>会员卡类型</label>
                                <select name="cardStatus" th:with="type=${@dict.getType('member_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>性别</label>
                                <select name="sex" th:with="type=${@dict.getType('sys_user_sex')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>剩余次数：</label>
                                <input type="text" name="timesNow"/>
                            </li>
                            <li>
                                <label>初始次数：</label>
                                <input type="text" name="timesBegin"/>
                            </li>
                            <li>
                                <label>创建人：</label>
                                <input type="text" name="createPeople"/>
                            </li>
                            <li>
                                <label>充值金额：</label>
                                <input type="text" name="moneyGet"/>
                            </li>
                            <li>
                                <label>优惠金额：</label>
                                <input type="text" name="moneyDis"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:member:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:member:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:member:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:member:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:member:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:member:remove')}]];
        var payFlag = [[${@permission.hasPermi('system:member:pay')}]];
        var cardStatusDatas = [[${@dict.getType('member_status')}]];
        var sexDatas = [[${@dict.getType('sys_user_sex')}]];
        var prefix = ctx + "system/member";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "会员管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'nameVip',
                    title: '会员姓名'
                },
                {
                    field: 'phone',
                    title: '手机号'
                },
                {
                    field: 'cardStatus',
                    title: '会员卡类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(cardStatusDatas, value);
                    }
                },
                {
                    field: 'sex',
                    title: '性别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(sexDatas, value);
                    }
                },
                {
                    field: 'timesNow',
                    title: '剩余次数'
                },
                {
                    field: 'timesBegin',
                    title: '初始次数'
                },
                {
                    field: 'createPeople',
                    title: '创建人'
                },
                {
                    field: 'moneyGet',
                    title: '实际充值金额',
                    formatter:function(value, row, index){
                        var val = value*100;
                        //金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
                        var str = (val/100).toFixed(2) + '';
                        var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
                        var dot = str.substring(str.length,str.indexOf("."))//取到小数部分搜索
                        var ret = intSum + dot;
                        return ret;
                    }
                },
                {
                    field: 'moneyDis',
                    title: '赠送金额',
                    formatter:function(value, row, index){
                        var val = value*100;
                        //金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
                        var str = (val/100).toFixed(2) + '';
                        var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
                        var dot = str.substring(str.length,str.indexOf("."))//取到小数部分搜索
                        var ret = intSum + dot;
                        return ret;
                    }
                },
                    {
                        field: 'moneyNow',
                        title: '剩余金额',
                        formatter:function(value, row, index){
                            var val = value*100;
                            //金额转换 分->元 保留2位小数 并每隔3位用逗号分开 1,234.56
                            var str = (val/100).toFixed(2) + '';
                            var intSum = str.substring(0,str.indexOf(".")).replace( /\B(?=(?:\d{3})+$)/g, ',' );//取到整数部分
                            var dot = str.substring(str.length,str.indexOf("."))//取到小数部分搜索
                            var ret = intSum + dot;
                            return ret;
                        }
                    },
                {
                    field: 'msg',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs ' + payFlag + '" href="javascript:void(0)" onclick="pay(\'' + row.id + '\')"><i class="fa fa-cart-plus"></i>消费</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
     <script th:inline="javascript">
         function pay(id){
             $.modal.confirm("确认消费吗？（想好了，不能退）",function (){
                     var res = $.operate.submit(ctx+"system/member/pay","post","json",{id:id});
                     console.log(res);
             }
             )
         }
     </script>
</body>
</html>
